package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class LoginPage extends AnyPage {
        
        @FindBy(name = "username")
        public WebElement usernameField;
        
        @FindBy(name = "password")
        public WebElement passwordField;
        
        @FindBy(name = "submit")
        public WebElement submitButton;
        
        @FindBy(id = "loginform")
        public WebElement loginform;
        
        public boolean isOnThisPage(){
    		return loginform.isDisplayed();
    	}

    	public HomePage logInwithValidCredentials(String username, String passw) {
    		usernameField.sendKeys(username);
    		passwordField.sendKeys(passw);
    		submitButton.click();
    		return MyPageFactory.getPage(driver, HomePage.class);
    	}
    	
    	public LoginPage logInwithWrongCredentials(String username, String passw) {
    		usernameField.sendKeys(username);
    		passwordField.sendKeys(passw);
    		submitButton.click();
    		return MyPageFactory.getPage(driver, LoginPage.class);
    	}
        
		@Override
		public void tryToOpen() {
			MyPageFactory.getPage(driver, InternalPage.class).logOut();			
		} 
}